// new
var buf1 = new Buffer(10);
var buf2 = new Buffer([10, 20, 30, 40, 50]);
var buf3 = new Buffer("www.runoob.com", "utf-8");
console.log(buf1.toString());
console.log(buf2.toString());
console.log(buf3.toString());

// write
var buf4 = new Buffer(256);
len = buf4.write('www.runoob.com');
console.log('写入字节数:'+len);
console.log(buf4.toString().substr(0,14));

buf5 = new Buffer(26);
for (var i = 0 ; i < 26 ; i++) {
  buf5[i] = i + 97;
}
console.log( buf5.toString('ascii'));       // 输出: abcdefghijklmnopqrstuvwxyz
console.log( buf5.toString('ascii',0,5));   // 输出: abcde
console.log( buf5.toString('utf8',0,5));    // 输出: abcde
console.log( buf5.toString(undefined,0,5)); // 默认使用 'utf8' 编码, 并输出: abcde

// toJson
var buf6 = new Buffer('www.runoob.com');
var json = buf6.toJSON(buf6);
console.log(json);

// concat
var buf7 = new Buffer('Hello ');
var buf8 = new Buffer('World');
var buf9 = Buffer.concat([buf7,buf8]);
console.log(buf9.toString());

// compare
var buf10 = new Buffer('123z');
var buf11 = new Buffer('123a');
console.log(buf10.compare(buf11));//ASCII比较


// copyTo
var buf12 = new Buffer('ABC');
var buf13 = new Buffer('1');
buf12.copy(buf13);
console.log('copy:'+buf13.toString()); //buf13为'3'=A ,buf13为3=ABC

// slice
var buf14 = new Buffer('abcdef');
var buf15 = buf14.slice(1);
console.log('slice:'+buf15.toString()); // 与字符串的裁剪类似

// length
var buf16 = new Buffer('arg');
console.log('length:'+buf16.length);